home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2001 / MacHack 2001.toast / pc / Sessions / Traut / ZStrings / Source / CrossPlatform / ZStringDictionary.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-06-23  |  2.3 KB  |  97 lines

  1. /*==================================================================
  2.     File:        ZStringDictionary.h
  3.     
  4.     Contains:    Class for parsing named ZStrings into platform-
  5.                 specific strings.
  6.  
  7.     Written by:    Eric Traut
  8.     
  9.     Copyright:    2000-2001 Connectix Corporation
  10.     
  11.     This source has been placed into the public domain by
  12.     Connectix Corporation. You have the right to modify, 
  13.     distribute or use this code without any legal limitations
  14.     or finanicial/licensing requirements. Connectix is not 
  15.     liable for any problems that result from the use of this 
  16.     code.
  17.     
  18.     If you have comments, feedback, questions, or would like
  19.     to submit bug fixes or updates to this code, please email
  20.     opensource@connectix.com.
  21. ==================================================================*/
  22.  
  23. #ifndef __ZSTRINGDICTIONARY__
  24. #define __ZSTRINGDICTIONARY__
  25.  
  26. #include "ZStringData.h"
  27. #include "ZStringParser.h"
  28. #include "ZString.h"
  29.  
  30.  
  31. class ZDictionaryEntry
  32. {
  33.     public:
  34.                                     // all methods are non-virtual
  35.                                 ZDictionaryEntry(
  36.                                     const char *    inNameStr,
  37.                                     Z_UInt16        inNameStrLen,
  38.                                     Z_Boolean        inCopyNameData);
  39.                                 ~ZDictionaryEntry(void);
  40.         
  41.         ZString                    mString;
  42.         const char *            mNameStr;
  43.         Z_UInt16                mNameStrLen;
  44.         Z_UInt16                mDictionaryOwnsNameData;
  45.         ZDictionaryEntry *        mNext;
  46. };
  47.  
  48. // The algorithm assumes the hash entry count is a power of two.
  49. const Z_UInt32        kZDictionaryHashEntries = 1024;
  50. const Z_UInt32        kZDictionaryEntryMask = (kZDictionaryHashEntries - 1);
  51.  
  52.  
  53. /*==================================================================
  54.     ZStringDictionary
  55. ==================================================================*/
  56.  
  57. class ZStringDictionary
  58. {
  59.     public:
  60.         // Construction & Destruction
  61.         ZStringDictionary();
  62.         
  63.         virtual
  64.         ~ZStringDictionary();
  65.  
  66.         static ZStringDictionary &
  67.         GetZStringDictionary()
  68.         {
  69.             check(sDictionary != NULL);
  70.             return *sDictionary;
  71.         }
  72.  
  73.         Z_Boolean
  74.         LookUpString(
  75.             const ZStringParseInfo &    inParseInfo,
  76.             ZString &                    outZString);
  77.  
  78.         void
  79.         RegisterString(
  80.             const ZStringParseInfo &    inParseInfo,
  81.             ZString &                    inZString);
  82.  
  83.         static Z_UInt32
  84.         HashString(
  85.             const char *                inName,
  86.             Z_UInt16                    inNameLen);
  87.         
  88.     private:
  89.         static ZStringDictionary *            sDictionary;
  90.         ZDictionaryEntry *                    mDictionaryHash[kZDictionaryHashEntries];
  91. };
  92.  
  93.  
  94.  
  95. #endif // __ZSTRINGDICTIONARY__
  96.  
  97.